func summaryRanges(nums []int) []string {
    n := len(nums)
    var res []string
    j := 0
    for i := 0; i < n; i++ {
        if i == n-1 || nums[i+1]-nums[i] != 1 {
            var sb strings.Builder
            sb.WriteString(strconv.Itoa(nums[j]))
            if j != i {
                sb.WriteString("->")
                sb.WriteString(strconv.Itoa(nums[i]))
            }
            res = append(res, sb.String())
            j = i + 1
        }
    }
    return res
}